package com.yanggu.mapreduce.groupingcomparator;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2020/2/7 16:30
 * @description:
 */
public class OrderBeanMapper extends Mapper<LongWritable, Text, OrderBean, NullWritable> {

    private OrderBean k = new OrderBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //0000001	Pdt_01	222.8

        //1. 获取一行
        String line = value.toString();

        //2. 封装数据
        String[] fields = line.split("\t");

        k.setId(Integer.parseInt(fields[0]));
        k.setPrice(Double.parseDouble(fields[2]));

        //3.写出
        context.write(k, NullWritable.get());
    }
}
